<template>
  <div class="pages">
    <el-card shadow="hover">
      <el-form :model="formDatas" inline status-icon :rules="rules" ref="logsRule" label-width="100px" class="logs-form">
        <el-form-item label="密码" prop="pass">
          <el-input type="password" v-model="formDatas.pass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPass">
          <el-input type="password" v-model="formDatas.checkPass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model.number="formDatas.age"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getList()">搜索</el-button>
          <el-button @click="resetForm('logsRule')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-card shadow="hover" v-loading="loading">
      <el-table :data="tableData" stripe style="width: 100%" border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="create_time" label="日期" width="180">
          <template slot-scope="scope">
            {{new Date(scope.row.create_time) | filterDate}}
          </template>
        </el-table-column>
        <el-table-column prop="user_email" label="账号" width="180"> </el-table-column>
        <el-table-column prop="" label="行为" width="180">
          <template slot-scope="scope">
            <el-tag size="small" effect="dark" :color="scope.row.code | filterUnlock(codeLabelValue, { value: 'color' })"> {{ scope.row.code | filterUnlock(codeLabelValue) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注"> </el-table-column>
      </el-table>
    </el-card>
    <el-card shadow="hover">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[100, 200, 300, 400]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { GET_LOGS_LIST } from "@/axios/api.js";

export default {
  name: "logs",
  components: {},
  data() {
    return {
      loading: false,
      formDatas: {
        pageNum: 1,
        pageSize: 10,
      },
      rules: {},
      tableData: [],

      codeLabelValue: [
        { value: 1, label: "登录失败", color: "#f56c6c" },
        { value: 2, label: "登录成功", color: "#67c23a" },
        { value: 3, label: "邮箱验证码", color: "#409eff" },
        { value: 4, label: "修改密码", color: "#909399" },
      ],

      currentPage: 10,
    };
  },
  created() {
    this.getList();
  },
  computed: {},
  watch: {},
  methods: {
    async getList() {
      this.loading = true;
      const { data, code, message } = await this.$http.get(GET_LOGS_LIST, this.formDatas);
      this.loading = false;
      if (code != 200) return this.$message.warning(message);
      this.tableData = data;
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
  },
};
</script>
<style lang='less' scoped>
.el-form-item {
  margin-bottom: 0;
}
.el-card {
  margin: 5px 0;
}
.el-tag--dark {
  border-color: transparent;
}
</style>